package com.appli.ImpossibleQuestSeason1;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class ImpossibleQuestSeason1Episode2 extends Activity implements OnClickListener {
	
	ArrayList <Integer> Keys;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.episode2);
        ((Button)findViewById(R.id.ButtonSkipEpisode)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonSkipEpisode)).setVisibility(View.GONE);
        ((Button)findViewById(R.id.ButtonAnswerEpisode1)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode2)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode3)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode4)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode5)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode6)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode7)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode8)).setOnClickListener(this);
        ((Button)findViewById(R.id.ButtonAnswerEpisode9)).setOnClickListener(this);
        ((ImageView)findViewById(R.id.ImageEpisode2)).setOnClickListener(this);
        Keys = new ArrayList<Integer>();
    }

	@Override
	public void onClick(View v) {
		try{
			switch (v.getId()){
				case R.id.ImageEpisode2:				
					Toast.makeText(this, "TRY TO FIND THE 4 MAGIC NUMBERS PATH. YOU HAVE TO START WITH THE FEETS SYMBOL", Toast.LENGTH_LONG).show();
				break;
				case R.id.ButtonAnswerEpisode1:
					Keys.add(Integer.valueOf(1));
				break;
				case R.id.ButtonAnswerEpisode2:
					Keys.add(Integer.valueOf(2));
				break;
				case R.id.ButtonAnswerEpisode3:
					Keys.add(Integer.valueOf(3));
				break;
				case R.id.ButtonAnswerEpisode4:
					Keys.add(Integer.valueOf(4));
				break;
				case R.id.ButtonAnswerEpisode5:
					Keys.add(Integer.valueOf(5));
				break;
				case R.id.ButtonAnswerEpisode6:
					Keys.add(Integer.valueOf(6));
				break;
				case R.id.ButtonAnswerEpisode7:
					Keys.add(Integer.valueOf(7));
				break;
				case R.id.ButtonAnswerEpisode8:
					Keys.add(Integer.valueOf(8));
				break;
				case R.id.ButtonAnswerEpisode9:
					Keys.add(Integer.valueOf(9));
				break;
				case R.id.ButtonSkipEpisode:
					Intent j = new Intent(this, ImpossibleQuestSeason1Episode3.class);
					startActivity(j);
				break;
			}
    	}catch (Exception E){
    		E.printStackTrace();
		}
    	boolean goodCode = false;
    	if (Keys != null && Keys.size() == 4){
    		if (Keys.get(0) != null && Keys.get(0).equals(Integer.valueOf(1))){
    			if (Keys.get(1) != null && Keys.get(1).equals(Integer.valueOf(4))){
    				if (Keys.get(2) != null && Keys.get(2).equals(Integer.valueOf(2))){
    					if (Keys.get(3) != null && Keys.get(3).equals(Integer.valueOf(9))){
    						goodCode = true;
    						Toast.makeText(this, " BZZZzzp !  Teleportation success !! ", Toast.LENGTH_LONG).show();
    						((Button)findViewById(R.id.ButtonSkipEpisode)).setVisibility(View.VISIBLE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode1)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode2)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode3)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode4)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode5)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode6)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode7)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode8)).setVisibility(View.GONE);
    						((Button)findViewById(R.id.ButtonAnswerEpisode9)).setVisibility(View.GONE);
    						Keys = new ArrayList<Integer>();
    					}
    				}
        		}	
    		}
    	}
    	
    	if (Keys != null && Keys.size() == 4 && goodCode == false){
    		Toast.makeText(this, "WRONG CODE !", Toast.LENGTH_LONG).show();
    		Keys = new ArrayList<Integer>();
    	}
	}
}